﻿using System;

namespace ContextualStateless
{
    public partial class StateMachine< TState, TTrigger, TContext >
    {
        internal class GuardedTriggerRepresentation : AbstractTriggerRepresentation
        {
            /// <summary>
            /// Target-state, which is achieved after successfull trigger transition.
            /// </summary>
            protected readonly TState _destination;

            #region Constructors

            public GuardedTriggerRepresentation( TTrigger trigger, TState destination, Func< TContext, bool > guard, LogicalActionHandler contextHandler )
                : base( trigger, guard, contextHandler )
            {
                _destination = destination;
            }

            public GuardedTriggerRepresentation( TTrigger trigger, TState destination, Func< TContext, bool > guard )
                : this( trigger, destination, guard, null )
            {
            }

            #endregion

            // ---------------------------------------------------------------------------------------------------------------------

            public override bool ResultsInTransitionFrom(TState source, object[] args, TContext context, out TState destination)
            {
                destination = _destination;
                return true;
            }
        }
    }
}
